import api from './index'

/**
 * 认证相关API模块
 */

export const authApi = {
  /**
   * 用户登录
   * @param {string} username - 用户名
   * @param {string} password - 密码
   * @returns {Promise<Object>} 登录响应数据
   */
  login: async (username, password) => {
    const response = await api.post('/auth/login', {
      username,
      password
    })
    return response.data
  },

  /**
   * 用户注册
   * @param {string} username - 用户名
   * @param {string} password - 密码
   * @param {string} email - 邮箱（可选）
   * @returns {Promise<Object>} 注册响应数据
   */
  register: async (username, password, email) => {
    const response = await api.post('/auth/register', {
      username,
      password,
      email
    })
    return response.data
  },

  /**
   * 用户退出登录
   * @returns {Promise<Object>} 退出响应数据
   */
  logout: async () => {
    const response = await api.post('/auth/logout')
    return response.data
  },

  /**
   * 获取当前用户信息
   * @returns {Promise<Object>} 用户信息
   */
  getCurrentUser: async () => {
    const response = await api.get('/auth/me')
    return response.data
  }
}

export default authApi